﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NHibernate;
using NHibernate.Criterion;

using Revis.VClinicNet.Core.Domain.Repository;

namespace Revis.VClinicNet.Core.Domain.Persistence.Nh
{
    public class EntryRepository : RepositoryBase<Entry>, IEntryRepository
    {
        public EntryRepository(ISessionFactory factor) :
            base(factor)
        {
        }

        public IList<Entry> PatientCard(long patientId)
        {
            IList<Entry> entries = Session.CreateCriteria<Entry>("e")
                .Add(Expression.Eq("e.RelatedTo.Id", patientId))
                .List<Entry>();
            return entries;
        }

        public Entry PatientEntry(long patientId, long entryId)
        {
            return Session.CreateCriteria<Entry>("e")
                .Add(Expression.Eq("e.Id", entryId))
                .Add(Expression.Eq("e.RelatedTo.Id", patientId))
                .UniqueResult<Entry>();
        }
    }
}
